bitkeeper revision 1.1159.17.24 (411bf61edgcR_nOyvkAutrxUxR2tRg)
authorkaf24@scramble.cl.cam.ac.uk <kaf24@scramble.cl.cam.ac.uk>
Thu, 12 Aug 2004 22:58:38 +0000 (22:58 +0000)
committerkaf24@scramble.cl.cam.ac.uk <kaf24@scramble.cl.cam.ac.uk>
Thu, 12 Aug 2004 22:58:38 +0000 (22:58 +0000)
Add close-on-exec to open fd's on /dev/mem and /dev/xen/evtchn in xend.

tools/python/xen/lowlevel/xu/xu.c

index 2a4f229feff6605a5ad117497be197fda6bd386c..d403099cec33ed90e3b8ad0d82546f7e8c80387d 100644 (file)
 #endif
 
 
+/* Set the close-on-exec flag on a file descriptor.  Doesn't currently bother
+ * to check for errors. */
+static void set_cloexec(int fd)
+{
+    int flags = fcntl(fd, F_GETFD, 0);
+
+    if ( flags < 0 )
+       return;
+
+    flags |= FD_CLOEXEC;
+    fcntl(fd, F_SETFD, flags);
+}
+
 /*
  * *********************** NOTIFIER ***********************
  */
@@ -197,6 +210,7 @@ static PyObject *xu_notifier_new(PyObject *self, PyObject *args)
         PyObject_Del((PyObject *)xun);
         return PyErr_SetFromErrno(PyExc_IOError);
     }
+    set_cloexec(xun->evtchn_fd);
 
     return (PyObject *)xun;
 }
@@ -896,6 +910,7 @@ static int __xu_port_connect(xu_port_object *xup)
         PyErr_SetString(port_error, "Could not open '/dev/mem'");
         return -1;
     }
+    set_cloexec(xup->mem_fd);
 
     /* Set the General-Purpose Subject whose page frame will be mapped. */
     (void)ioctl(xup->mem_fd, _IO('M', 1), (unsigned long)xup->remote_dom);